package com.share.device.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.share.common.log.annotation.Log;
import com.share.common.log.enums.BusinessType;
import com.share.common.security.annotation.RequiresPermissions;
import com.share.device.domain.Cabinet;
import com.share.device.service.ICabinetService;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.utils.poi.ExcelUtil;
import com.share.common.core.web.page.TableDataInfo;

/**
 * 充电宝柜机
 * 
 * @author         
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/cabinet")
@Tag(name = "充电宝柜机", description = "APIs for managing Cabinet")
public class CabinetController extends BaseController
{
    @Autowired
    private ICabinetService cabinetService;

    /**
     * 查询充电宝柜机列表
     */
    @RequiresPermissions("cabinet:cabinet:list")
    @GetMapping("/list")
    @Operation(summary = "充电宝柜机列表")
    public TableDataInfo list(Cabinet cabinet)
    {
        startPage();
        List<Cabinet> list = cabinetService.selectCabinetList(cabinet);
        return getDataTable(list);
    }

    /**
     * 导出充电宝柜机列表
     */
    @RequiresPermissions("cabinet:cabinet:export")
    @Log(title = "充电宝柜机", businessType = BusinessType.EXPORT)
    @Operation(summary = "导出充电宝柜机列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cabinet cabinet)
    {
        List<Cabinet> list = cabinetService.selectCabinetList(cabinet);
        ExcelUtil<Cabinet> util = new ExcelUtil<Cabinet>(Cabinet.class);
        util.exportExcel(response, list, "充电宝柜机数据");
    }

    /**
     * 获取充电宝柜机详细信息
     */
    @RequiresPermissions("cabinet:cabinet:query")
    @Operation(summary = "获取充电宝柜机详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cabinetService.selectCabinetById(id));
    }

    /**
     * 新增充电宝柜机
     */
    @RequiresPermissions("cabinet:cabinet:add")
    @Operation(summary = "新增充电宝柜机")
    @Log(title = "充电宝柜机", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cabinet cabinet)
    {
        return toAjax(cabinetService.insertCabinet(cabinet));
    }

    /**
     * 修改充电宝柜机
     */
    @RequiresPermissions("cabinet:cabinet:edit")
    @Operation(summary = "修改充电宝柜机")
    @Log(title = "充电宝柜机", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cabinet cabinet)
    {
        return toAjax(cabinetService.updateCabinet(cabinet));
    }

    /**
     * 删除充电宝柜机
     */
    @RequiresPermissions("cabinet:cabinet:remove")
    @Operation(summary = "删除充电宝柜机")
    @Log(title = "充电宝柜机", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cabinetService.deleteCabinetByIds(ids));
    }

    /**
     * 获取充电宝柜机全部详细信息
     * @param id
     * @return
     */
    @Operation(summary = "获取充电宝柜机全部详细信息")
    @GetMapping(value = "/getAllInfo/{id}")
    public AjaxResult getAllInfo(@PathVariable("id") Long id)
    {
        return success(cabinetService.getAllInfo(id));
    }
}
